package com.headhunter.company;

import java.rmi.*;

import com.headhunter.server.Headhunter;

public class HeadhunterClient {
	private static Headhunter headhunter;

	public static void main(String[] args) {
		System.setSecurityManager(new RMISecurityManager());
		try {
			String url = "rmi://localhost:1099/Headhunter";
			headhunter = (Headhunter) Naming.lookup(url);

			sendJobPosting1();
			sendJobPosting2();
			sendJobPosting3();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static void sendJobPosting1() {
		ApplicationRecordImpl ar1 = new ApplicationRecordImpl("Google",
				"www.google.com");
		ar1.addDegree("CS");
		ar1.addQualification("C++");
		try {
			int result = headhunter.addApplicationRecord(ar1);
			if (result > 0)
				System.out.println("Job posting created with id " + result);
			else
				System.out.println("Error at creating job posting");
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}

	private static void sendJobPosting2() {
		ApplicationRecordImpl ar2 = new ApplicationRecordImpl("Oracle",
				"www.oracle.com");
		ar2.addDegree("CS");
		ar2.addQualification("PLSQL");
		ar2.addQualification("Java");
		try {
			int result = headhunter.addApplicationRecord(ar2);
			if (result > 0) {
				System.out.println("Job posting created with id " + result);
			} else {
				System.out.println("Error at creating job posting");
			}
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}

	private static void sendJobPosting3() {
		ApplicationRecordImpl ar3 = new ApplicationRecordImpl("Texas Instruments",
				"www.texasinstruments.com");
		ar3.addDegree("EE");
		ar3.addDegree("CS");
		ar3.addQualification("FPGA");
		ar3.addQualification("Wireless");
		try {
			int result = headhunter.addApplicationRecord(ar3);
			if (result > 0) {
				System.out.println("Job posting created with id " + result);
			} else {
				System.out.println("Error at creating job posting");
			}
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}
}